<?php
include 'config.php';

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $stmt = $conn->prepare("SELECT notice_title, notice_text, publish_time FROM notices WHERE id = ?");
    $stmt->bind_param("i", $id);
    $stmt->execute();
    $result = $stmt->get_result();

    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        $title = $row['notice_title'];
        $content = $row['notice_text'];
        $publishTime = date('Y-m-d H:i', strtotime($row['publish_time']));
    } else {
        echo "未找到该公告。";
        exit;
    }
    $stmt->close();
} else {
    echo "参数错误。";
    exit;
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title><?php echo $title; ?></title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap">
    <style>
        body {
            font-family: 'Inter', 'PingFang SC', 'Helvetica Neue', sans-serif;
            background: #f8f9ff;
            margin: 0;
            padding: 20px;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            background: white;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        .notice-title {
            font-size: 24px;
            font-weight: 600;
            margin-bottom: 10px;
        }

        .publish-time {
            font-size: 14px;
            color: #666;
            margin-bottom: 20px;
        }

        .notice-content {
            line-height: 1.6;
        }

        .back-button {
            display: inline-block;
            margin-top: 20px;
            padding: 10px 20px;
            background: #6c5ce7;
            color: white;
            text-decoration: none;
            border-radius: 5px;
        }

        .back-button:hover {
            background: #5a4dcb;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1 class="notice-title"><?php echo $title; ?></h1>
        <p class="publish-time">发布时间: <?php echo $publishTime; ?></p>
        <div class="notice-content">
            <?php echo $content; ?>
        </div>
        <a href="index.php" class="back-button">返回首页</a>
    </div>
</body>
</html>